/*
 *
 * Copyright (c) 2020 The Raptor Authors. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef RAPTOR_LITE_SRC_COMMON_CONNECTION_ID_H_
#define RAPTOR_LITE_SRC_COMMON_CONNECTION_ID_H_

#include <stdint.h>

namespace raptor {

namespace internal {
constexpr uint32_t InvalidConnectionId = (uint32_t)(~0);
constexpr int kIndexOffset             = 18;
constexpr uint16_t kMaxContainerId     = 1 << 9;
constexpr uint32_t kMaxConnectionIndex = 1 << 18;
constexpr int kIndexBitsMask            = kMaxConnectionIndex - 1;

uint32_t BuildConnectionId(uint16_t magic, uint16_t id, uint32_t index);
bool VerifyConnectionId(uint32_t cid, uint16_t magic);
uint16_t GetMagicNumber(uint32_t cid);
uint16_t GetContainerId(uint32_t cid);
uint32_t GetConnectionIndex(uint32_t cid);
} // namespace internal
} // namespace raptor
#endif // RAPTOR_LITE_SRC_COMMON_CONNECTION_ID_H_
